package com.jiahui.dao;

import android.content.Context;

import com.jiahui.model.HomeModel;

public class HomeModelDao {

	private AccountDao accountDao;

	private IncomeDao incomeDao;

	public HomeModelDao(Context context) {

		accountDao = new AccountDao(context);

		incomeDao = new IncomeDao(context);
	}

	public HomeModel query(int year, int month, int day) {

		HomeModel homeModel = new HomeModel();

		String sumAccount = accountDao.querySumMoney();

		if ("".equals(sumAccount) || sumAccount == null) {
			homeModel.setSumAccount("0");
		} else {
			homeModel.setSumAccount(sumAccount);
		}

		String currentMonthSumAccount = accountDao.querySumMoneyByMonth(year,
				month);
		if ("".equals(currentMonthSumAccount) || currentMonthSumAccount == null) {
			homeModel.setCurrentMonthSumAccount("0");
		} else {
			homeModel.setCurrentMonthSumAccount( currentMonthSumAccount);
		}
		String todaySumAccount = accountDao
				.querySumMoneyByDay(year, month, day);

		if ("".equals(todaySumAccount) || todaySumAccount == null) {
			homeModel.setTodaySumAccount("0");
		} else {
			homeModel.setTodaySumAccount(  todaySumAccount);
		}

		String sumIncome = incomeDao.querySumMoney();

		if ("".equals(sumIncome) || null == sumIncome) {
			homeModel.setSumIncome("0");
		} else {
			homeModel.setSumIncome( sumIncome);
		}

		String currentMonthSumIncome = incomeDao.querySumMoneyByMonth(year,
				month);

		if ("".equals(currentMonthSumIncome) || null == currentMonthSumIncome) {
			homeModel.setCurrentMonthSumIncome("0");
		} else {
			homeModel.setCurrentMonthSumIncome( currentMonthSumIncome);
		}

		String todaySumIncome = incomeDao.querySumMoneyByDay(year, month, day);

		if ("".equals(todaySumIncome) || null == todaySumIncome) {
			homeModel.setTodaySumIncome("0");
		} else {
			homeModel.setTodaySumIncome( todaySumIncome);
		}

		return homeModel;

	}

}
